package com.vf.admin.client.tx.remove;

import cn.hutool.core.util.ObjectUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.tencentyun.TLSSigAPIv2;
import com.vf.admin.client.common.ClientBaseController;
import com.vf.admin.client.service.AppUserService;
import com.vf.admin.common.entity.Result;
import com.vf.admin.miaodong.entity.AppUser;
import com.vf.admin.utils.httpqingqiu.HttpPostUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;

import static com.vf.admin.client.tx.utils.TxIm.ImSignatureGeneration;
import static com.vf.admin.client.tx.utils.txConfig.*;

/**
 * <p>Title : </p>
 * <p>Description : </p>
 * <p>DevelopTools : IDEA</p>
 * <p>DevelopSystem : Windows11</p>
 *
 * @Author : zxw
 * @Date 2023/8/8 16:42
 */

@RestController
@RequestMapping("/app/remove")
public class RemoveController extends ClientBaseController {

    @Autowired
    private AppUserService appUserService;


    /**
     * 获取全部用户信息
     */
    @RequestMapping(value = "/list")
    public Result list() {

        List<AppUser> appUsers = appUserService.allList();
        System.out.println("总数量：" + appUsers.size());

        if (ObjectUtil.isNotEmpty(appUsers) & appUsers.size() > 0) {

            appUsers.forEach(e -> {

                //导入操作
                String signatureGeneration = ImSignatureGeneration();
                String url = "https://console.tim.qq.com/v4/im_open_login_svc/account_import?sdkappid=" + SDKAPPID + "&identifier=" + ADMIN + "&usersig=" + signatureGeneration + "&random=99999999&contenttype=json";
                JSONObject jsonObject = new JSONObject();
                jsonObject.put("UserID", e.getTengxuncode().toString());
                jsonObject.put("Nick", e.getNick());
                jsonObject.put("FaceUrl", e.getPic());
                System.out.println(jsonObject);
                //发送请求
                String body = HttpPostUtils.getInstance().sendPostBody(url, "", jsonObject.toJSONString());
                System.out.println(body);
            });


        }
//        //总条数
//        int size = appUsers.size();
//        int fetchSize = 100;
//        int keyToken  = 0;
//        for (int i = 0; i < appUsers.size(); i+=fetchSize) {
//            if (i + fetchSize > size){
//                fetchSize = size -i;
//            }
//            List<AppUser> temp = appUsers.subList(i, i + fetchSize);
//            System.out.println("_____" + temp.size());
//            //循环插入到腾讯code
//            if (ObjectUtil.isNotEmpty(temp) && temp.size()>0){
//
//
//            }
//
//
//            keyToken++;
//
//        }


//        //
//        List<String> temp = new ArrayList<>();
//        appUsers1.forEach(e -> {
//            temp.add(String.valueOf(e.getTengxuncode()));
//        });
//        String signatureGeneration = ImSignatureGeneration();
//        String url = "https://console.tim.qq.com/v4/im_open_login_svc/multiaccount_import?sdkappid=" + SDKAPPID + "&identifier=" + ADMIN + "&usersig=" + signatureGeneration + "&random=99999999&contenttype=json";
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("Accounts", temp);
//        //发送请求
//        String resultContent = HttpPostUtils.getInstance().sendPostBody(url, "", jsonObject.toJSONString());
        return this.sucessJSON(null);
    }


}
